package de.hska.reka.websockets.Parser;

import net.sf.ezmorph.bean.MorphDynaBean;
import net.sf.json.JSONObject;

public class JsonRPCParser {

	public Object deserialize(String jsonRPCString) {
		JSONObject jsonObject = JSONObject.fromObject(jsonRPCString);
		if(jsonObject.containsKey("error")) {
			return (JSONObject.toBean(jsonObject, JsonRpcResult.class));
		} else {
			return (JSONObject.toBean(jsonObject, JsonRpcPackage.class));
		}
	}

	public String serialize(JsonRpcPackage rpcPackage) {
		JSONObject jsonObject = JSONObject.fromObject(rpcPackage);
		return jsonObject.toString();
	}

	public String serialize(JsonRpcResult rpcPackage) {
		JSONObject jsonObject = JSONObject.fromObject(rpcPackage);
		return jsonObject.toString();
	}
}
